#! /bin/bash

# Author: Huoty <sudohuoty@163.com>
# CreateTime: 2020-08-19 09:45:13
# Script starts from here:

echo "========= Compile:"
if [[ "$*" =~ ".cpp" ]]; then
    CC="g++ -Wall -std=c++11"
    if [[ `uname -s` == "Darwin" ]]; then
        CC="${CC} -stdlib=libc++"
    fi
else
    CC="gcc -Wall"
fi

TMPDIR=$(dirname $(mktemp -u))
OUTFILE="${TMPDIR}/cplus-tmp-out"
if [[ -f $OUTFILE ]]; then
    /bin/rm -f $OUTFILE
fi

$CC "$@" -o $OUTFILE

if [[ $? == 0 ]]; then
    echo "========= Run:"
    $OUTFILE
fi

if [[ -f $OUTFILE ]]; then
    /bin/rm -f $OUTFILE
fi
